Write a Rust function to check if a given string is a pangram.
Write a Rust function to check if a given string is a pangram.
398
22-Jun-2023
Aryan Kumar
23-Jun-2023Sure, here is a Rust function to check if a given string is a pangram:
Rust
This function first defines a function called is_pangram that takes a string as input and returns a bool value. The function first initializes a variable called seen_letters to an array of 26 bool values, initialized to false. Then, the function iterates through the string, checking if each character is in the alphabet. If the character is in the alphabet, then the corresponding element in the seen_letters array is set to true. Finally, the function checks if all the elements in the seen_letters array are true. If they are, then the function returns true. Otherwise, the function returns false.
The main function of the program then calls the is_pangram function with the string "The quick brown fox jumps over the lazy dog" as input. The result of the function call is then printed to the console.
To run the program, you can save it as a file called is_pangram.rs and then compile it using the following command:
Code snippet
Once the program is compiled, you can run it using the following command:
Code snippet
This will print the following output to the console:
Code snippet